package com.neu.envprotection.feedback.dao.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.neu.envprotection.feedback.dao.entity.Feedback;
import com.neu.envprotection.feedback.dto.req.GetAirQualityReqDto;
import com.neu.envprotection.feedback.dto.req.GetFeedBackReqDto;
import com.neu.envprotection.feedback.dto.resp.*;
import org.apache.ibatis.annotations.Select;

import java.util.List;

/**
 * <p>
 *  Mapper 接口
 * </p>
 *
 * @author ${author}
 * @date 2024/06/07
 */
public interface FeedbackMapper extends BaseMapper<Feedback> {

    List<GetFeedBackRespDto> queryFeedback(Page page, GetFeedBackReqDto condition);

    List<GetAirQualityRespDto> queryAirQuality(Page page, GetAirQualityReqDto condition);

    GetFeedbackDetailRespDto getDetailById(Integer feedbackId);

    GetAirQualityDetailRespDto getAirDetailById(Integer airQualityId);
    @Select("SELECT p.provience_name AS provinceName, COUNT(f.rank_id) AS AQICount " +
            "FROM provience p " +
            "LEFT JOIN env_grid g ON p.id = g.provience_id " +
            "LEFT JOIN feedback f ON g.id = f.grid_id " +
            "WHERE f.rank_id >= 3 " +
            "GROUP BY p.provience_name")
    List<ReportChinaChartsRespDto> getProvinceAQI();

    @Select("SELECT COUNT(DISTINCT eg.provience_id) AS provinceCover, COUNT(DISTINCT eg.city_id) AS cityCover " +
            "FROM feedback f INNER JOIN env_grid eg ON f.grid_id = eg.id")
    GetCityCoverRespDto getCoverData();

    @Select("SELECT " +
            "COUNT(id) AS airQualityPointCount, " +
            "COUNT(CASE WHEN rank_id <= 2 THEN 1 END) AS goodAirDays, " +
            "COUNT(CASE WHEN rank_id >= 3 THEN 1 END) AS pollutedAirDays " +
            "FROM feedback")
    GetAQICountRespDto getCountData();


}
